package com.mofang.ticketing.user.serve.project.controller;


import com.mofang.ticketing.common.core.dto.PrimaryIdDTO;
import com.mofang.ticketing.common.core.page.PageResult;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.core.urls.user.project.ProjectUrl;
import com.mofang.ticketing.common.log.SystemLog;
import com.mofang.ticketing.user.serve.project.dto.request.*;
import com.mofang.ticketing.user.serve.project.dto.response.ProjectDetailRespDTO;
import com.mofang.ticketing.user.serve.project.dto.response.ProjectListPageRespDTO;
import com.mofang.ticketing.user.serve.project.dto.response.ProjectSelectRespDTO;
import com.mofang.ticketing.user.serve.project.dto.response.ProjectUserListPageRespDTO;
import com.mofang.ticketing.user.serve.project.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LGC
 */
@Api(tags = "项目管理")
@RestController
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @ApiOperation(value = "项目详情")
    @PostMapping(value = ProjectUrl.PROJECT_DETAIL)
    public Result<ProjectDetailRespDTO> projectDetail(@RequestBody @Validated PrimaryIdDTO dto) {
        return Result.success(projectService.projectDetail(dto));
    }

    @ApiOperation(value = "项目分页列表")
    @PostMapping(value = ProjectUrl.PROJECT_LIST_PAGE)
    public Result<PageResult<ProjectListPageRespDTO>> projectListPage(@RequestBody @Validated ProjectListPageReqDTO dto) {
        return Result.page(PageResult.getPageResult(projectService.projectListPage(dto)));
    }

    @SystemLog
    @ApiOperation(value = "项目新增")
    @PostMapping(value = ProjectUrl.PROJECT_ADD)
    public Result<Void> projectAdd(@RequestBody @Validated ProjectAddReqDTO dto) {
        projectService.projectAdd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "项目修改")
    @PostMapping(value = ProjectUrl.PROJECT_UPDATE)
    public Result<Void> projectUpdate(@RequestBody @Validated ProjectUpdateReqDTO dto) {
        projectService.projectUpdate(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "项目删除")
    @PostMapping(value = ProjectUrl.PROJECT_DEL)
    public Result<Void> projectDel(@RequestBody @Validated PrimaryIdDTO dto) {
        projectService.projectDel(dto);
        return Result.success();
    }

    @ApiOperation(value = "所有项目选择")
    @PostMapping(value = ProjectUrl.PROJECT_SELECT)
    public Result<List<ProjectSelectRespDTO>> projectSelect() {
        return Result.success(projectService.projectSelect());
    }

    @ApiOperation(value = "项目用户分页列表")
    @PostMapping(value = ProjectUrl.PROJECT_USER_LIST_PAGE)
    public Result<PageResult<ProjectUserListPageRespDTO>> projectUserListPage(@RequestBody @Validated ProjectUserListPageReqDTO dto) {
        return Result.page(PageResult.getPageResult(projectService.projectUserListPage(dto)));
    }

    @SystemLog
    @ApiOperation(value = "项目用户删除")
    @PostMapping(value = ProjectUrl.PROJECT_USER_DEL)
    public Result<Void> projectUserDel(@RequestBody @Validated ProjectUserDelReqDTO dto) {
        projectService.projectUserDel(dto);
        return Result.success();
    }

}
